﻿<%@ WebHandler Language="C#" Class="Product_DeleteImage" %>

using System;
using System.Web;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Data;
using System.IO;
public class Product_DeleteImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/html";
        int IDimg = 0;
        try { IDimg = Convert.ToInt32(context.Request["id"].ToString()); }
        catch { IDimg = 0; }
        int numReturn = -1;

        TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamManager().SelectOne(IDimg);
        if (_TblHinhAnhSanPhamEntity != null)
        {
            if (!string.IsNullOrEmpty(_TblHinhAnhSanPhamEntity.Image))
            {
                string filePath = HttpContext.Current.Request.MapPath(_TblHinhAnhSanPhamEntity.Image);
                try { File.Delete(filePath); }
                catch { }
            }
        }
        try
        {
            numReturn = new TblHinhAnhSanPhamManager().DeleteById(IDimg);
        }
        catch { numReturn = -1; }

        context.Response.Write(numReturn.ToString());
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}